package org.rabbitmq.test7;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.rabbitmq.utils.RabbitMqUtils;

public class ReceiveLogsTopic02 {

    public static final String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws Exception {
        //获取信道
        Channel channel = RabbitMqUtils.getChannel();
        //声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME,"topic");
        //声明队列
        String queueName = "Q2";
        channel.queueDeclare(queueName,false,false,false,null);
        //绑定交换机器
        channel.queueBind(queueName,EXCHANGE_NAME,"*.*.rabbit");
        channel.queueBind(queueName,EXCHANGE_NAME,"lazy.#");
        System.out.println("Q2等待接收消息");
        DeliverCallback deliverCallback = (consumerTage,message) ->{
            System.out.println(new String(message.getBody(),"UTF-8"));
        };
        //接收消息
        channel.basicConsume(queueName,false,deliverCallback,consumerTag->{});
    }
}
